<h1><?php echo $fund['name'] ?></h1>
<ul id="breadcrumb">
	<li>ครุภัณฑ์</li>
</ul>
<div id="content">
	<div class="search">
		<form method="get">
		  <label>ค้นหา</label> <input type="text" name="search" value="<?php echo (!empty($_GET['search']))?$_GET['search']:'' ?>" />
		<?php if(level_data('view')): ?>
		&nbsp;&nbsp;<label>หน่วยงาน </label><?php echo form_dropdown('agency_id', get_agency_option($fund['id']),$agency_id,'','ทั้งหมด'); ?>
		<?php endif; ?>
		  <input type="submit" value="<?php echo lang('search'); ?>" class="button" />
		</form>
	</div>
	
<table class="list">
	<tr>
		<th width="70">ลำดับที่</th>
		<th>รายการ</th>
		<th width="70">จำนวน</th>
		<th width="100">วันที่ได้มา</th>
		<th width="150">ราคาทุน</th>
		<th width="150">จำนวนเงิน</th>
		<th width="110">อายุการใช้งาน</th>
		<th width="150">ค่าเสื่อมราคาปี</th>
		<th width="150">ราคาสุทธิ</th>
		<th>หมายเหตุ</th>
		<th width="200"><a href="asset/form" class="button"><span class="icon_text addnew"></span>เพิ่มรายการ</a></th>
	</tr>
	<?php 
	foreach($result as $key => $item):

		$item_budget = get_year_budget($item['date_record']);
		$current_budget = get_year_budget(date('Y-m-d'));
		$year_past = $current_budget - $item_budget;
		if(strtotime(date('Y-m-d'))<strtotime(date('Y').'-09-30'))$year_past--;
		$price = NULL;
		$depreciation = NULL;
		$net = NULL;
		if($year_past <= $item['lifetime'])
		{
			$price = $item['cost'];		
			$depreciation = ($item['cost']/$item['lifetime'])*(rest_month($item['date_record'])/12);
			$net = $price - $depreciation;
			
			if($item_budget != $current_budget)
			{	
				$depreciation = $item['cost']/$item['lifetime'];
				$price = $net - ($depreciation * ($year_past-1));
				$net = $price - $depreciation;
			}	
		}
	?>
	<tr <?php echo cycle($key) ?>>
		<td class="center"><?php echo $key + 1; ?></td>
		<td><?php echo anchor('asset/view/'.$item['id'], $item['title']); ?></td>
		<td class="center"><?php echo $item['unit']; ?></td>
		<td class="center"><?php echo mysql_to_date($item['date_record'], TRUE); ?></td>
		<td class="num"><?php echo number_format($item['cost'], 2); ?></td>
		<td class="num"><?php echo (empty($price)) ? '' : number_format($price, 2); ?></td>
		<td class="center"><?php echo (empty($price)) ? '' : $item['lifetime']; ?></td>
		<td class="num"><?php echo (empty($price)) ? '' : number_format($depreciation, 2); ?></td>
		<td class="num"><?php echo ($net < 0) ? '' :number_format($net, 2); ?></td>
		<td><?php echo $item['ps']; ?></td>
		<td class="center"><a href="asset/form/<?php echo $item['id'] ?>" class="button"><span class="icon_text edit"></span>แก้ไข</a> <a href="asset/asset_class/delete/<?php echo $item['id'] ?>" onclick="return confirm('<?php echo lang('confirm_delete')?>')" class="button"><span class="icon_text cancel"></span>ลบ</a></td>
	</tr>
	<? endforeach; ?>
</table>

	<?php echo $pagination ?>
</div>